package Q4;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class ChatServer {

    private static User adminUser = new User("admin", "123456");

    public static User getAdminUser() {
        return adminUser;
    }

    public static void main(String[] args) {

        ServerSocket ss = null;
        try {
            //1. 创建ServerSocket对象
            ss = new ServerSocket(8887);
            //2. 等待客户端的请求
            while (true) {
                System.out.println("等待用户接入...");
                Socket s = ss.accept();
                // 启动线程处理客户端请求
                System.out.println("服务器收到客户端请求");
                System.out.println("客户端" + s.getInetAddress() + "连接成功！");
                new Thread(new ChatServerRunnable(s)).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭socket
            try {
                if (ss != null) {
                    ss.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
